<template>
  <div class="ruleSetDetail">
    <el-drawer
      title="我是标题"
      :visible.sync="drawerVisible"
      size="70%"
      :with-header="false"
      :close-on-press-escape="false"
      :wrapper-closable="false"
      :before-close="cancelForm"
    >
      <div class="drawerForm">
        <div class="pageTitle">
          <div class="titleText">{{ formData.ruleSetName }}规则集</div>
          <slot name="header" />
        </div>
        <div class="formScrollbar">
          <el-form ref="formData" class="formContent" :model="formData" label-width="96px" label-suffix="：">
            <el-row class="ruleSetInfo">
              <el-col :span="12">
                <el-form-item label="ID编码" prop="ruleSetId">
                  <span v-if="drawerType !== 'copy'" class="fontBold">{{ formData.ruleSetId }}</span>
                </el-form-item>
                <el-form-item v-if="type === 'file'" label="变量库" prop="parameterModuleIdList">
                  <el-cascader
                    v-if="drawerType !== 'view'"
                    v-model="formData.parameterModuleIdList"
                    :options="variableModelOption"
                    :props="{ multiple: true, emitPath: false }"
                    :show-all-levels="false"
                    clearable
                    class="w360"
                    collapse-tags
                  ></el-cascader>
                  <el-cascader
                    v-else
                    v-model="formData.parameterModuleIdList"
                    popper-class="cascaderView"
                    :options="formData.variableModelOptionList"
                    :props="{ multiple: true, emitPath: false }"
                    :show-all-levels="false"
                    class="w360 cascaderView"
                    collapse-tags
                  ></el-cascader>
                  <el-button
                    v-if="drawerType !== 'view'"
                    type="primary"
                    class="carryBtn"
                    @click="handleClick('add')"
                  >
                    添加规则
                  </el-button>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="规则集名称" prop="ruleSetName">
                  <el-input
                    v-if="drawerType === 'copy'"
                    v-model="formData.ruleSetName"
                    class="w360 show-word-limit"
                    maxlength="20"
                    show-word-limit
                  />
                  <span v-else class="fontBold">{{ formData.ruleSetName }}规则集</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="searchBox">
              <el-input
                v-model="filterText"
                placeholder="规则名称模糊查询"
                @keyup.enter.native="handleSearch('search')"
              ></el-input>
              <el-button type="primary" @click="handleSearch('search')">查询</el-button>
              <el-button @click="handleSearch('clear')">重置</el-button>
            </el-row>
            <virtual-list
              ref="virtualList"
              class="virtualselect-list"
              item-class="ruleItem"
              :data-key="'propId'"
              :data-sources="filterRuleData"
              :data-component="itemComponent"
              :keeps="10"
              :extra-props="{
                drawerType,
                prepositionRuleList,
                formData,
                type
              }"
            ></virtual-list>
          </el-form>
        </div>

        <div class="drawerFooter" align="right">
          <el-button @click="cancelForm">退出页面</el-button>
          <el-button v-if="drawerType === 'edit'" type="primary" @click="submitForm">保存变更</el-button>
          <el-button v-if="drawerType === 'copy'" type="primary" @click="submitForm">保存</el-button>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { randomString } from '@/utils/index'
import {
  initRuleSet,
  getFactModeOptionList,
  getFactModeAndComparatorToStandardSpecificationOptionList,
  editRuleSet
} from '@/api/rule-management'
import virtualList from 'vue-virtual-scroll-list'
import ruleDetail from './ruleDetail.vue'
import defaultSettings from '@/settings'
import { generateUUID, postMessage, receivedMessage } from '@/utils/index'

export default {
  name: 'RuleSetDetail',
  components: {
    'virtual-list': virtualList
  },
  props: {
    type: {
      type: String,
      default: ''
    },
    conditionalRelationOption: {
      type: Array,
      default: () => {
        return []
      }
    },
    variableModelOption: {
      type: Array,
      default: () => {
        return []
      }
    },
    factModeToComparatorOption: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      filterText: '',
      filterRuleData: [],
      firstLoad: false,
      drawerVisible: false,
      historyFormData: {},
      formData: {
        ruleSetId: null,
        ruleSetName: '',
        parameterModuleIdList: [],
        ruleDataList: []
      },
      drawerType: '',

      factModeOption: [],
      factModeObj: {},
      standardSpecificationOption: {},
      itemComponent: ruleDetail,
      initRuleSetRequestId: generateUUID(),
      getFactModeOptionListRequestId: generateUUID(),
      getFactModeAndComparatorToStandardSpecificationOptionListRequestId: generateUUID(),
      editRuleSetRequestId: generateUUID()
    }
  },
  computed: {
    prepositionRuleList() {
      let arr = []
      this.formData.ruleDataList.forEach((item, index) => {
        if (item.ruleName) {
          arr.push({
            label: item.ruleName,
            value: item.ruleId,
            propId: item.propId
          })
        }
      })
      return arr
    }
  },
  watch: {
    'formData.parameterModuleIdList': {
      handler() {
        if (this.drawerType !== 'view') {
          this.getFactModeOption()
        }
      }
      // deep: true
    },
    prepositionRuleList: {
      handler(list) {
        if (this.drawerType !== 'view') {
          let prepositionRulePropIds = list.map((item) => {
            return item.propId
          })
          this.formData.ruleDataList.forEach((item) => {
            if (!prepositionRulePropIds.includes(item.prepositionRuleData.propId)) {
              item.prepositionRuleData = {}
            }
          })
        }
      },
      deep: true
    }
  },
  mounted() {
    receivedMessage(this.dataHandle)
  },
  methods: {
    dataHandle(result) {
      let self = this
      let e = defaultSettings.isWPF ? result : { data: JSON.parse(result) }
      if (e.data.webInfo.requestId === self.initRuleSetRequestId) {
        let res = e.data.response
        if (res.success) {
          self.transFormData(self.drawerType, res.data)
        } else {
          self.$message.error(res.message)
        }
      } else if (e.data.webInfo.requestId === self.getFactModeOptionListRequestId) {
        self.setFactModeOptionList(e.data.response)
      } else if (
        e.data.webInfo.requestId === self.getFactModeAndComparatorToStandardSpecificationOptionListRequestId
      ) {
        self.setFactModeAndComparatorToStandardSpecificationOptionList(e.data.response)
      } else if (e.data.webInfo.requestId === self.editRuleSetRequestId) {
        let res = e.data.response
        if (res.success) {
          self.afterEditRuleSet(res)
        } else {
          self.$notify.error(res.message)
        }
      }
    },
    is(type, currentRow) {
      this.filterText = ''
      this.firstLoad = true
      this.drawerVisible = true
      this.drawerType = type
      if (type === 'view') {
        this.transFormData(type, currentRow)
      } else {
        if (defaultSettings.isWPF || defaultSettings.isCEF) {
          this.initRuleSetRequestId = generateUUID()
          let message = {
            RequestUrl: process.env.VUE_APP_URL + '/ruleSet/init',
            RequestMethod: 'POST',
            Headers: {
              contentType: 'application/json'
            },
            QueryParameter: {},
            RequestBody: { ruleSetId: currentRow.ruleSetId },
            WebInfo: {
              requestId: this.initRuleSetRequestId
            }
          }
          postMessage(message)
        } else {
          initRuleSet({ ruleSetId: currentRow.ruleSetId }).then((res) => {
            this.transFormData(type, res.data)
          })
        }
      }
    },
    transStandardSpecificationOption(data) {
      const addDisabled = (data) => {
        data.forEach((item) => {
          item.disabled = false
          if (item.children) {
            addDisabled(item.children)
          }
        })
      }
      addDisabled(data)
      return data
    },
    transFormData(type, formData) {
      if (type === 'copy') {
        formData.ruleSetId = undefined
      }
      formData.ruleDataList.forEach((item) => {
        item.propId = item.ruleId
        if (type === 'copy') {
          item.ruleId = undefined
        }
        if (type !== 'view' && item.prepositionRuleData.value) {
          item.prepositionRuleData.propId = item.prepositionRuleData.value
        }
        if (this.type === 'file') {
          item.conditionDataList.forEach((row) => {
            if (type === 'copy') {
              row.conditionId = undefined
            }
            row.visible = false
            row.factMode = row.factMode.map((factModeRow) => {
              return Number(factModeRow) == factModeRow ? Number(factModeRow) : factModeRow
            })
            if (row.standardSpecification?.[0] == 1004) {
              row.enterValue = row.standardSpecification[1]
              row.standardSpecification = [1004]
            } else {
              if (row.standardSpecification.length > 0 && [1, 2, 3].includes(row.comparator)) {
                let arr = []
                let arr1 = row.standardSpecification[row.standardSpecification.length - 1].split('@!')
                let index = row.standardSpecification.findIndex((tem) => tem.indexOf(arr1[0] + '@!') == 0)
                if (index != -1) {
                  for (let i = index; i < row.standardSpecification.length; i++) {
                    let tem = []
                    for (let j = 0; j < index; j++) {
                      tem.push(
                        Number(row.standardSpecification[j]) == row.standardSpecification[j]
                          ? Number(row.standardSpecification[j])
                          : row.standardSpecification[j]
                      )
                    }
                    tem.push(row.standardSpecification[i])
                    arr.push(tem)
                  }
                }
                row.standardSpecification = arr
              } else {
                row.standardSpecification = row.standardSpecification.map((standardRow) => {
                  return Number(standardRow) == standardRow ? Number(standardRow) : standardRow
                })
              }
            }
          })
        } else {
          item.conditionDataList.forEach((row) => {
            row.factModeName = '获取"' + row.factMode + '"字段值'
          })
        }
      })
      this.formData = formData
      this.filterRuleData = formData.ruleDataList
      console.log(this.filterRuleData)
      // console.log(this.formData)
      this.historyFormData = JSON.parse(JSON.stringify(formData))
    },
    transTreeObj(data, obj) {
      data.forEach((item) => {
        obj[item.value] = item
        if (item.children) {
          this.transTreeObj(item.children, obj[item.value])
        }
      })
      return obj
    },
    getFactModeOption() {
      if (this.formData.parameterModuleIdList.length === 0) {
        this.factModeOption = []
        this.factModeObj = {}
        this.formData.ruleDataList.forEach((item) => {
          item.conditionDataList.forEach((row) => {
            row.factMode = []
            row.nearestFactMode = ''
            row.comparator = ''
            row.standardSpecification = []
          })
        })
        this.getFactModeAndComparatorToStandardSpecificationOptionList()
      } else {
        if (defaultSettings.isWPF || defaultSettings.isCEF) {
          this.getFactModeOptionListRequestId = generateUUID()
          let message = {
            RequestUrl: process.env.VUE_APP_URL + '/ruleSet/getFactModeOptionList',
            RequestMethod: 'POST',
            Headers: {
              contentType: 'application/json'
            },
            QueryParameter: {},
            RequestBody: { parameterModuleIdList: this.formData.parameterModuleIdList },
            WebInfo: {
              requestId: this.getFactModeOptionListRequestId
            }
          }
          postMessage(message)
        } else {
          getFactModeOptionList({
            parameterModuleIdList: this.formData.parameterModuleIdList
          }).then((res) => {
            this.setFactModeOptionList(res)
          })
        }
      }
    },
    setFactModeOptionList(res) {
      this.factModeOption = res.data
      this.factModeObj = this.transTreeObj(this.factModeOption, {})

      this.formData.ruleDataList.forEach((item) => {
        item.conditionDataList.forEach((row) => {
          if (row.factMode.length > 0) {
            let obj = this.factModeObj
            let arr = []
            row.factMode.forEach((factModeItem) => {
              obj = obj?.[factModeItem]
              if (obj) arr.push(obj.type + '-' + obj.value)
            })
            if (!obj?.value) {
              row.factMode = []
              row.nearestFactMode = ''
              row.comparator = ''
              row.standardSpecification = []
            } else {
              let len = arr.length
              for (let i = len - 1; i >= 0; i--) {
                if (arr[i].indexOf('1-') != -1) {
                  row.nearestFactMode = arr[i].split('-')[1]
                  break
                }
              }
            }
          } else {
            row.factMode = []
            row.nearestFactMode = ''
            row.comparator = ''
            row.standardSpecification = []
          }
        })
      })
      this.getFactModeAndComparatorToStandardSpecificationOptionList()
    },
    getFactModeAndComparatorToStandardSpecificationOptionList() {
      if (defaultSettings.isWPF || defaultSettings.isCEF) {
        this.getFactModeAndComparatorToStandardSpecificationOptionListRequestId = generateUUID()
        let message = {
          RequestUrl:
            process.env.VUE_APP_URL + '/ruleSet/getFactModeAndComparatorToStandardSpecificationOptionList',
          RequestMethod: 'POST',
          Headers: {
            contentType: 'application/json'
          },
          QueryParameter: {},
          RequestBody: { parameterModuleIdList: this.formData.parameterModuleIdList },
          WebInfo: {
            requestId: this.getFactModeAndComparatorToStandardSpecificationOptionListRequestId
          }
        }
        postMessage(message)
      } else {
        getFactModeAndComparatorToStandardSpecificationOptionList({
          parameterModuleIdList: this.formData.parameterModuleIdList
        }).then((res) => {
          this.setFactModeAndComparatorToStandardSpecificationOptionList(res)
        })
      }
    },
    setFactModeAndComparatorToStandardSpecificationOptionList(res) {
      this.firstLoad = false
      let obj = {}
      let data = res.data
      for (let key in data) {
        obj[key] = this.transStandardSpecificationOption(data[key])
      }
      this.standardSpecificationOption = obj

      this.formData.ruleDataList.forEach((item) => {
        item.conditionDataList.forEach((row) => {
          if (row.factMode.length > 0 && row.comparator) {
            let standardSpecificationOption = this.transTreeObj(
              this.standardSpecificationOption[row.nearestFactMode + '-' + row.comparator] ?? [],
              {}
            )
            if ([1, 2, 3].includes(row.comparator)) {
              let result = true
              row.standardSpecification.every((standard) => {
                let obj = standardSpecificationOption
                standard.forEach((row) => {
                  obj = obj?.[row]
                })
                if (!obj?.value) {
                  result = false
                  return false
                }
                return true
              })
              if (!result) row.standardSpecification = []
            } else {
              let obj = standardSpecificationOption
              row.standardSpecification.forEach((standard) => {
                obj = obj?.[standard]
              })
              if (!obj?.value) {
                row.standardSpecification = []
              }
            }
          }
        })
      })
    },
    handleClick(name, index, conditionIndex) {
      let conditionDataList = []
      if (name.indexOf('condition') != -1) {
        conditionDataList = this.formData.ruleDataList[index].conditionDataList
      }
      switch (name) {
        case 'add':
          this.formData.ruleDataList.push({
            propId: randomString(11),
            ruleName: '',
            ruleRemark: '',
            prepositionRuleData: {},
            conditionalRelation: 1,
            conditionDataList: []
          })
          break
        case 'del':
          this.formData.ruleDataList.splice(index, 1)
          break
        case 'conditionAdd':
          conditionDataList.push({
            visible: false,
            description: '',
            factMode: [],
            comparator: '',
            enterValue: '',
            standardSpecification: []
          })
          break
        case 'conditionDel':
          conditionDataList.splice(conditionIndex, 1)
          break
        case 'conditionCopy':
          conditionDataList.push({ ...conditionDataList[conditionIndex], conditionId: undefined })
          break
        case 'conditionMoveUp':
          if (conditionIndex === 0) return
          this.handlePositionSwap(conditionDataList, conditionIndex - 1, conditionIndex)
          break
        case 'conditionMoveDown':
          if (conditionIndex === conditionDataList.length - 1) return
          this.handlePositionSwap(conditionDataList, conditionIndex, conditionIndex + 1)
          break
      }
    },
    handlePositionSwap(arr, i, j) {
      let obj = JSON.parse(JSON.stringify(arr[i]))
      arr.splice(i, 1, arr[j])
      arr.splice(j, 1, obj)
    },
    handleChangePrepositionRule(val, index) {
      if (val) {
        this.prepositionRuleList.every((item) => {
          if (item.propId === val) {
            this.formData.ruleDataList[index].prepositionRuleData.label = item.label
            this.formData.ruleDataList[index].prepositionRuleData.value = item.value
            return false
          }
          return true
        })
      } else {
        this.formData.ruleDataList[index].prepositionRuleData.label = ''
        this.formData.ruleDataList[index].prepositionRuleData.value = undefined
      }
    },

    getPrepositionRuleArr(propId, arr) {
      this.formData.ruleDataList.forEach((item) => {
        if (item.prepositionRuleData.propId === propId) {
          arr.push(item.propId)
          this.getPrepositionRuleArr(item.propId, arr)
        }
      })
      return arr
    },
    // 事实方式
    handleChangeFactMode(val, index, conditionIndex) {
      if (val.length === 0) {
        this.formData.ruleDataList[index].conditionDataList[conditionIndex].nearestFactMode = undefined
        this.formData.ruleDataList[index].conditionDataList[conditionIndex].comparator = undefined
        this.formData.ruleDataList[index].conditionDataList[conditionIndex].standardSpecification = []
      } else {
        let arr = []
        let obj = this.factModeObj
        val.forEach((item) => {
          obj = obj[item]
          arr.push(obj.type + '-' + obj.value)
        })
        let row = this.formData.ruleDataList[index].conditionDataList[conditionIndex]
        let len = arr.length
        for (let i = len - 1; i >= 0; i--) {
          if (arr[i].indexOf('1-') != -1) {
            let nearestFactMode = arr[i].split('-')[1]
            row.nearestFactMode = nearestFactMode
            if (this.factModeToComparatorOption[nearestFactMode]) {
              let comparatorOption = this.factModeToComparatorOption[nearestFactMode].map((item) => {
                return item.value
              })
              if (!comparatorOption.includes(row.comparator)) {
                row.comparator = undefined
                row.standardSpecification = []
              } else {
                this.handleChangeComparator(row.comparator, index, conditionIndex)
              }
            }
            break
          }
        }
      }
    },
    //
    handleChangeComparator(val, index, conditionIndex) {
      let row = this.formData.ruleDataList[index].conditionDataList[conditionIndex]
      if (val) {
        if (this.standardSpecificationOption[row.nearestFactMode + '-' + row.comparator]) {
          let standardSpecificationOption = this.transTreeObj(
            this.standardSpecificationOption[row.nearestFactMode + '-' + row.comparator] ?? [],
            {}
          )

          if ([1, 2, 3].includes(val)) {
            let result = true
            row.standardSpecification.every((item) => {
              if (Array.isArray(item)) {
                let obj = standardSpecificationOption
                item.forEach((row) => {
                  obj = obj?.[row]
                })
                if (!obj?.value) {
                  result = false
                  return false
                }
                return true
              } else {
                result = false
                return false
              }
            })
            if (!result) row.standardSpecification = []
          } else {
            let obj = standardSpecificationOption
            row.standardSpecification.forEach((item) => {
              obj = obj?.[item]
            })
            if (!obj?.value) {
              row.standardSpecification = []
            }
          }
        }
      } else {
        row.standardSpecification = []
      }
    },
    // 标准规范
    getStandardSpecification(data, val, comparator) {
      let newData = JSON.parse(JSON.stringify(data))
      // let newData = data
      if (val.length > 0 && [1, 2, 3].includes(comparator)) {
        let standardSpecification = [...new Set(val.toString().split(','))]
        const setDisabled = (itemData, level) => {
          level++
          for (let i = 0; i < itemData.length; i++) {
            if (standardSpecification.includes(itemData[i].value.toString()) && level === val[0].length) {
              itemData.forEach((item) => {
                item.disabled = false
                // this.$set(item, 'disabled', false)
                if (item.children) {
                  setDisabled(item.children, level)
                }
              })
              if (itemData[i].children) {
                setDisabled(itemData[i].children, level)
              }
              break
            } else {
              itemData[i].disabled = true
              // this.$set(itemData[i], 'disabled', true)
            }
            if (itemData[i].children) {
              setDisabled(itemData[i].children, level)
            }
          }
        }
        setDisabled(newData, 0)
      } else {
        const setDisabled = (itemData) => {
          itemData.forEach((item) => {
            item.disabled = false
            // this.$set(item, 'disabled', false)
            if (item.children) {
              setDisabled(item.children)
            }
          })
        }
        setDisabled(newData)
      }
      return newData
    },
    // 提交表单
    submitForm() {
      let formData = JSON.parse(JSON.stringify(this.formData))
      let validate = true
      formData.ruleDataList.forEach((item, index) => {
        this.$refs['formRuleData' + index][0].validate((valid) => {
          validate = validate && valid
        })
        item.conditionDataList.forEach((row) => {
          if (row.standardSpecification.length > 0 && [1, 2, 3].includes(row.comparator)) {
            let standardSpecification = [...new Set(row.standardSpecification.toString().split(','))]
            row.standardSpecification = standardSpecification
          }
          if (row.standardSpecification?.[0] === 1004) {
            row.standardSpecification = [1004, row.enterValue]
          }
        })
      })
      if (!validate) return
      let result = true
      let self = this
      formData.ruleDataList.every((item, index) => {
        item.conditionDataList.every((row, rowIndex) => {
          if (row.factMode.length === 0) {
            result = false
            self.$notify.warning('第' + (index + 1) + '个规则第' + (rowIndex + 1) + '行条件请选择事实方式')
            return false
          }
          if (!row.comparator) {
            result = false
            self.$notify.warning('第' + (index + 1) + '个规则第' + (rowIndex + 1) + '行条件请选择比较符')
            return false
          }
          if (row.standardSpecification.length === 0) {
            result = false
            self.$notify.warning('第' + (index + 1) + '个规则第' + (rowIndex + 1) + '行条件请选择标准规范')
            return false
          } else {
            if (row.standardSpecification?.[0] === 1004 && row.enterValue.indexOf('@!') != -1) {
              result = false
              self.$notify.warning(
                '第' +
                  (index + 1) +
                  '个规则第' +
                  (rowIndex + 1) +
                  '行条件标准规范为选择输入的话，输入值不能包含"@!"'
              )
              return false
            }
          }
          return true
        })
        return result
      })
      if (!result) return
      if (defaultSettings.isWPF || defaultSettings.isCEF) {
        this.editRuleSetRequestId = generateUUID()
        let message = {
          RequestUrl: process.env.VUE_APP_URL + '/ruleSet/edit',
          RequestMethod: 'POST',
          Headers: {
            contentType: 'application/json'
          },
          QueryParameter: {},
          RequestBody: formData,
          WebInfo: {
            requestId: this.editRuleSetRequestId
          }
        }
        postMessage(message)
      } else {
        editRuleSet(formData).then((res) => {
          this.afterEditRuleSet(res)
        })
      }
    },
    afterEditRuleSet(res) {
      this.$notify.success((this.drawerType === 'edit' ? '保存变更' : '保存') + '成功')
      this.drawerType = 'edit'
      let data = res.data
      this.formData.ruleSetId = data.ruleSetId
      this.formData.ruleDataList.forEach((item, index) => {
        item.ruleId = data.ruleDataList[index].ruleId
        item.propId = item.ruleId
        item.conditionDataList.forEach((row, rowIndex) => {
          row.conditionId = data.ruleDataList[index].conditionDataList[rowIndex].conditionId
        })
      })
      this.historyFormData = JSON.parse(JSON.stringify(this.formData))

      // this.transFormData('edit', res.data)
      // this.$emit('close')
      // this.drawerVisible = false
    },
    whetherAsk() {
      if (this.drawerType === 'copy' && !this.formData.ruleSetId) {
        return false
      } else {
        // 比较变量库
        if (
          JSON.stringify(this.formData.parameterModuleIdList.sort()) !=
          JSON.stringify(this.historyFormData.parameterModuleIdList.sort())
        ) {
          return true
        }

        // 判断规则
        let ruleDataList = this.formData.ruleDataList
        let historyRuleList = this.historyFormData.ruleDataList
        if (ruleDataList.length === historyRuleList.length) {
          let result = false
          for (let i = 0; i < ruleDataList.length; i++) {
            if (ruleDataList[i].ruleName != historyRuleList[i].ruleName) {
              result = true
              break
            }
            if (ruleDataList[i].ruleRemark != historyRuleList[i].ruleRemark) {
              result = true
              break
            }
            if (ruleDataList[i].prepositionRuleId != historyRuleList[i].prepositionRuleId) {
              result = true
              break
            }
            if (ruleDataList[i].conditionalRelation != historyRuleList[i].conditionalRelation) {
              result = true
              break
            }
            // ruleDataList[i].conditionDataList.forEach((row) => {
            //   if (row.standardSpecification.length > 0 && [1, 2, 3].includes(row.comparator)) {
            //     row.standardSpecification = [...new Set(row.standardSpecification.toString().split(','))]
            //   }
            // })
            if (
              JSON.stringify(
                ruleDataList[i].conditionDataList.map((item) => {
                  return {
                    comparator: item.comparator,
                    conditionId: item.conditionId,
                    description: item.description,
                    factMode: item.factMode,
                    standardSpecification: item.standardSpecification
                  }
                })
              ) !=
              JSON.stringify(
                historyRuleList[i].conditionDataList.map((item) => {
                  return {
                    comparator: item.comparator,
                    conditionId: item.conditionId,
                    description: item.description,
                    factMode: item.factMode,
                    standardSpecification: item.standardSpecification
                  }
                })
              )
            ) {
              result = true
              break
            }
          }
          return result
        } else {
          return true
        }
      }
    },
    // 取消表单
    cancelForm() {
      if (this.drawerType === 'view') {
        this.$emit('close')
        this.drawerVisible = false
      } else {
        let result = this.whetherAsk()
        if (result) {
          this.$confirm('是否保存变更?', '提示', {
            distinguishCancelAndClose: true,
            confirmButtonText: '保存',
            cancelButtonText: '不保存',
            type: 'warning'
          })
            .then(() => {
              this.submitForm()
            })
            .catch((action) => {
              if (action === 'cancel') {
                this.$emit('close')
                this.drawerVisible = false
              }
            })
        } else {
          this.$emit('close')
          this.drawerVisible = false
        }
      }
    },
    handleSearch(name) {
      if (name === 'clear') {
        this.filterText = ''
      }
      this.filterRuleData = this.formData.ruleDataList.filter((item) => {
        return item.ruleName.indexOf(this.filterText) != -1
      })
      this.$nextTick(() => {
        this.$refs.virtualList.scrollToIndex(0) // 滚动到顶部
      })
    }
  }
}
</script>
<style lang="less" scoped>
.ruleSetDetail {
  height: 100%;
  /deep/label {
    font-weight: 500;
  }

  .drawerForm {
    display: flex;
    flex-direction: column;
    height: 100%;

    .w360 {
      width: 360px;
    }
    .cascaderView /deep/.el-tag__close {
      display: none;
    }
    .formScrollbar {
      width: calc(100% - 64px);
      overflow-x: auto;
      height: calc(100% - 100px);
      margin: 0px 32px;
    }
    .formContent {
      width: 1278px;
      height: 100%;
      display: flex;
      flex-direction: column;
      .fontBold {
        font-weight: bold;
      }
      .searchBox {
        display: flex;
        margin-bottom: 20px;
        .el-input {
          width: 300px;
          margin-right: 20px;
        }
      }
    }
    .show-word-limit {
      /deep/.el-input__inner {
        padding-right: 45px;
      }
    }

    .carryBtn {
      position: absolute;
      right: 24px;
    }
    .ruleSetInfo {
      margin-bottom: 6px;
    }
    .virtualselect-list {
      flex: 1;
      margin-bottom: 15px;
      overflow-y: auto;

      /deep/.ruleItem:first-of-type {
        border-top: 1px dashed #b9c8dc;
      }
      /deep/.ruleItem {
        padding: 24px 0;
        border-bottom: 1px dashed #b9c8dc;
      }
    }
  }

  .pageTitle {
    padding: 15px 32px;
    font-size: 16px;
    color: #333;
    font-weight: bold;
    .titleText {
      display: inline;
    }
  }
  .drawerFooter {
    padding: 0 32px;
    float: right;
  }
}
</style>
<style lang="scss">
// @import '@/styles/element-variables.scss';
.checkStrictlyPopper {
  .el-cascader-panel {
    .el-scrollbar .el-cascader-node:has(.hiddenPrefixIcon) {
      .el-radio,
      .el-checkbox {
        display: none;
      }
      .el-cascader-node__label {
        padding-left: 0;
      }
    }
  }
}

.cascaderView {
  .el-cascader-panel {
    .el-scrollbar {
      .el-checkbox,
      .el-icon-check {
        display: none;
      }
      .el-cascader-node__label {
        padding-left: 0;
      }

      .el-cascader-node.in-active-path,
      .el-cascader-node.is-selectable.in-checked-path,
      .el-cascader-node.is-active {
        color: #606266;
        font-weight: unset;
      }
    }
  }
}
</style>
